package com.livedocumentation.client.facebook;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.livedocumentation.client.GWTEntryPoint;
import com.livedocumentation.client.facebook.sdk.FBCore;
import com.livedocumentation.client.facebook.sdk.JSOModel;
import com.livedocumentation.client.model.User;

public class FacebookAboutMe {

	public FacebookAboutMe(final FBCore fbCore) {

		fbCore.api("/me", new AsyncCallback<JavaScriptObject>() {

			@Override
			public void onFailure(Throwable caught) {

			}

			@Override
			public void onSuccess(JavaScriptObject result) {

				JSOModel jso = result.cast();

				GWT.log("logged " + result);

				String id = jso.get("id");

				String name = jso.get("name");

				String email = jso.get("email");

				User me = new User(id, name, email);

				GWTEntryPoint.facebookUser = me;
			}
		});
	}
}
